//
//  SpatialSearchHandler.m
//  dataGathering
//
//  Created by apple on 14/12/23.
//  Copyright (c) 2014年 shuili. All rights reserved.
//

#import "SpatialSearchHandler.h"
#import "SearchRectangleMode.h"
#import "SearchHandrawingMode.h"
#import "SearchLineMode.h"
#import "SearchSketchMode.h"
#import "SearchBufferAreaMode.h"

@interface SpatialSearchHandler ()
@property(nonatomic, assign)AGSMapView *mapview;
@property(nonatomic, retain)SearchBaseMode *currentMode;
@property(nonatomic, assign)SpatialSearchMode currentModeType;

@end

@implementation SpatialSearchHandler

-(instancetype)initWithMapView :(AGSMapView*)mapview
{
    self = [super init];
    if(self){
        _mapview = mapview;
    }
    return self;
}

-(void)setMode :(SpatialSearchMode)mode
{
    _currentModeType = mode;
    switch (mode) {
        case SpatialSearchModeRectangle:
            _currentMode = [[SearchRectangleMode alloc] initWithMapview:_mapview];
            break;
        case SpatialSearchModePolygon:
            _currentMode = [[SearchSketchMode alloc] initWithMapview:_mapview];
            break;
        case SpatialSearchModeSketch:
            _currentMode = [[SearchHandrawingMode alloc] initWithMapview:_mapview];
            break;
        case SpatialSearchModeLine:
            _currentMode = [[SearchLineMode alloc] initWithMapview:_mapview];
            break;
        case SpatialSearchModeBufferArea:
            _currentMode = [[SearchBufferAreaMode alloc] initWithMapview:_mapview];
            break;
            
        default:
            break;
    }
    _currentMode.delegate = self;
}

-(void)SearchBaseMode:(SearchBaseMode *)mode didFinishDrawing:(AGSPolygon *)polygon
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(SpatialSearchHandler:didFinishDrawing::)]) {
        [self.delegate SpatialSearchHandler:self didFinishDrawing:polygon :_currentModeType];
    }
}

-(void)stop
{
    [_currentMode stop];
}

@end
